//
//  CYYSignUpView.m
//  LetsParty
//
//  Created by YG on 15/9/22.
//  Copyright (c) 2015年 LetsPartyTeam. All rights reserved.
//

#import "CYYSignUpView.h"

@interface CYYSignUpView ()

@property (nonatomic, strong) CYYCustomTextField * nameTextField;//用户名
@property (nonatomic, strong) CYYCustomTextField * mobilePhoneTextField;//手机号
@property (nonatomic, strong) CYYCustomTextField * emailTextField;//邮箱
@property (nonatomic, strong) CYYCustomTextField * firstPasswordTextField;//首次输入密码
@property (nonatomic, strong) CYYCustomTextField * secondPasswordTextField;//二次输入密码
@property (nonatomic, strong) UIButton * registButton;//注册按钮

- (void)initializeUserInterafce;

@end

@implementation CYYSignUpView

#pragma mark - init
- (instancetype)init{
    if (self = [super init]) {
        [self initializeUserInterafce];
    }
    return self;
}

#pragma mark - private methods
- (void)initializeUserInterafce{
    [self addSubview:self.nameTextField];
    [self addSubview:self.mobilePhoneTextField];
    [self addSubview:self.emailTextField];
    [self addSubview:self.firstPasswordTextField];
    [self addSubview:self.secondPasswordTextField];
    [self addSubview:self.registButton];
}

- (CYYCustomTextField *)haveTextFieldWithIndex:(NSInteger)index{
    CYYCustomTextField * textField = [[CYYCustomTextField alloc]initWithFrame:CGRectMake(20, 10 + 50 * index, 280, 40) adjustWidth:NO];
    textField.placeholder = @[@"请输入姓名",@"请输入真实的手机号",@"请输入真实的邮箱",@"请输入密码",@"请再次输入密码"][index];
    textField.alpha = 0.8;
    textField.textAlignment = NSTextAlignmentLeft;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField.borderStyle = UITextBorderStyleNone;
    textField.textColor = [UIColor whiteColor];
    [textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    if (index == 3 || index == 4) {
        textField.secureTextEntry = YES;
        
    }
    NSArray * imageNameArray = @[@"iconfont-mingzi1",@"iconfont-shouji-1",@"iconfont-youxiang",@"iconfont-mima",@"iconfont-mima"];
    UIButton * cButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cButton.frame = DHFlexibleFrame(CGRectMake(0, 0, 20, 20), NO);
    [cButton setImage:[UIImage imageNamed:imageNameArray[index]] forState:UIControlStateNormal];
    textField.leftView = cButton;
    textField.leftViewMode = UITextFieldViewModeAlways;
    return textField;
}

#pragma mark - getter
-(CYYCustomTextField *)nameTextField{
    if (!_nameTextField) {
        _nameTextField = ({
            [self haveTextFieldWithIndex:0];
        });
    }
    return _nameTextField;
}

-(CYYCustomTextField *)mobilePhoneTextField{
    if (!_mobilePhoneTextField) {
        _mobilePhoneTextField = ({
            [self haveTextFieldWithIndex:1];
        });
    }
    return _mobilePhoneTextField;
}

- (CYYCustomTextField *)emailTextField{
    if (!_emailTextField) {
        _emailTextField = ({
            [self haveTextFieldWithIndex:2];
        });
    }
    return _emailTextField;
}

-(CYYCustomTextField *)firstPasswordTextField{
    if (!_firstPasswordTextField) {
        _firstPasswordTextField = ({
            [self haveTextFieldWithIndex:3];
        });
    }
    return _firstPasswordTextField;
}

-(CYYCustomTextField *)secondPasswordTextField{
    if (!_secondPasswordTextField) {
        _secondPasswordTextField = ({
            [self haveTextFieldWithIndex:4];
        });
    }
    return _secondPasswordTextField;
}

- (UIButton *)registButton{
    if (!_registButton) {
        _registButton = ({
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = DHFlexibleFrame(CGRectMake(20, 210 + 50, 280, 40), NO);
            button.backgroundColor = [UIColor whiteColor];
            button.layer.cornerRadius = 20 * DHFlexibleVerticalMutiplier();
            [button setTitle:@"完成注册" forState:UIControlStateNormal];
            [button setTitleColor:COLOR_RGB(61, 142, 233, 1) forState:UIControlStateNormal];
            button;
        });
    }
    return _registButton;
}


@end
